<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.2.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" integrity="sha256-XOqroi11tY4EFQMR9ZYwZWKj5ZXiftSx36RRuC3anlA=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"example.com","root":"/","images":"/images","scheme":"Muse","darkmode":false,"version":"8.20.0","exturl":false,"sidebar":{"position":"left","width_expanded":320,"width_dual_column":240,"display":"post","padding":18,"offset":12},"copycode":{"enable":false,"style":null},"fold":{"enable":false,"height":500},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="设计了一个算法可以求解资源受限的项目调度问题">
<meta property="og:type" content="article">
<meta property="og:title" content="资源受限项目调度程序RCPSP">
<meta property="og:url" content="http://example.com/2024/05/06/%E8%B5%84%E6%BA%90%E5%8F%97%E9%99%90%E9%A1%B9%E7%9B%AE%E8%B0%83%E5%BA%A6%E7%A8%8B%E5%BA%8FRCPSP/index.html">
<meta property="og:site_name" content="TUUG个人主页">
<meta property="og:description" content="设计了一个算法可以求解资源受限的项目调度问题">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/images/%E6%B4%BB%E5%8A%A8%E4%BC%98%E5%85%88%E5%85%B3%E7%B3%BB.png">
<meta property="og:image" content="http://example.com/images/%E9%BB%98%E8%AE%A4%E9%A1%BA%E5%BA%8F%E8%B0%83%E5%BA%A6%E6%96%B9%E6%A1%88.png">
<meta property="og:image" content="http://example.com/images/%E5%90%AF%E5%8F%91%E8%A7%84%E5%88%99%E8%B0%83%E5%BA%A6%E6%96%B9%E6%A1%88.png">
<meta property="article:published_time" content="2024-05-06T09:02:52.336Z">
<meta property="article:modified_time" content="2024-05-06T12:25:55.752Z">
<meta property="article:author" content="TUUG">
<meta property="article:tag" content="项目调度，启发式规则">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/images/%E6%B4%BB%E5%8A%A8%E4%BC%98%E5%85%88%E5%85%B3%E7%B3%BB.png">


<link rel="canonical" href="http://example.com/2024/05/06/%E8%B5%84%E6%BA%90%E5%8F%97%E9%99%90%E9%A1%B9%E7%9B%AE%E8%B0%83%E5%BA%A6%E7%A8%8B%E5%BA%8FRCPSP/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://example.com/2024/05/06/%E8%B5%84%E6%BA%90%E5%8F%97%E9%99%90%E9%A1%B9%E7%9B%AE%E8%B0%83%E5%BA%A6%E7%A8%8B%E5%BA%8FRCPSP/","path":"2024/05/06/资源受限项目调度程序RCPSP/","title":"资源受限项目调度程序RCPSP"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>资源受限项目调度程序RCPSP | TUUG个人主页</title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css">
<!-- hexo injector head_end end --><link rel="alternate" href="/atom.xml" title="TUUG个人主页" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">TUUG个人主页</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">成为你想成为的人</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li><li class="menu-item menu-item-schedule"><a href="/schedule/" rel="section"><i class="fa fa-calendar fa-fw"></i>日程表</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%97%AE%E9%A2%98%E4%BB%8B%E7%BB%8D"><span class="nav-number">1.</span> <span class="nav-text">问题介绍</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%A4%BA%E4%BE%8B"><span class="nav-number">2.</span> <span class="nav-text">示例</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%90%AF%E5%8F%91%E8%A7%84%E5%88%99%E6%B1%82%E8%A7%A3"><span class="nav-number">3.</span> <span class="nav-text">启发规则求解</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%B1%82%E8%A7%A3%E7%BB%93%E6%9E%9C"><span class="nav-number">4.</span> <span class="nav-text">求解结果</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="TUUG"
      src="/images/%E9%AB%98%E8%BE%BE%E5%A4%B4%E5%83%8F.png">
  <p class="site-author-name" itemprop="name">TUUG</p>
  <div class="site-description" itemprop="description">心有所向，无问西东</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">4</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/John-start" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;John-start" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="/tr666666@qq.com" title="E-Mail → tr666666@qq.com" rel="noopener me"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://blog.csdn.net/faithful1" title="CSDN → https:&#x2F;&#x2F;blog.csdn.net&#x2F;faithful1" rel="noopener me" target="_blank"><i class="fab fa-csdn fa-fw"></i>CSDN</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
    <div class="sidebar-inner sidebar-blogroll">
      <div class="links-of-blogroll animated">
        <div class="links-of-blogroll-title"><i class="fa fa-globe fa-fw"></i>
          链接
        </div>
        <ul class="links-of-blogroll-list">
            <li class="links-of-blogroll-item">
              <a href="https://blog.csdn.net/faithful1" title="https:&#x2F;&#x2F;blog.csdn.net&#x2F;faithful1" rel="noopener" target="_blank">CSDN</a>
            </li>
        </ul>
      </div>
    </div>
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2024/05/06/%E8%B5%84%E6%BA%90%E5%8F%97%E9%99%90%E9%A1%B9%E7%9B%AE%E8%B0%83%E5%BA%A6%E7%A8%8B%E5%BA%8FRCPSP/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/%E9%AB%98%E8%BE%BE%E5%A4%B4%E5%83%8F.png">
      <meta itemprop="name" content="TUUG">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="TUUG个人主页">
      <meta itemprop="description" content="心有所向，无问西东">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="资源受限项目调度程序RCPSP | TUUG个人主页">
      <meta itemprop="description" content="设计了一个算法可以求解资源受限的项目调度问题">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          资源受限项目调度程序RCPSP
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2024-05-06 17:02:52 / 修改时间：20:25:55" itemprop="dateCreated datePublished" datetime="2024-05-06T17:02:52+08:00">2024-05-06</time>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>7.3k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>13 分钟</span>
    </span>
</div>

            <div class="post-description">设计了一个算法可以求解资源受限的项目调度问题</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><h1 id="问题介绍"><a href="#问题介绍" class="headerlink" title="问题介绍"></a>问题介绍</h1><p>资源受限项目调度问题（Resource-Constrained Project Scheduling Problem，RCPSP）是一个经典的优化问题，涉及在有限资源的情况下安排项目任务，以最大化某种指标，比如项目完成时间、资源利用率或成本最小化等。在许多实际应用中，资源受限是常见的，例如在制造业、建筑业、信息技术和项目管理等领域。</p>
<p>在资源受限项目调度问题中，通常会给定以下几个方面的限制和条件：</p>
<ol>
<li>任务： 项目被分解为一系列可执行的任务，每个任务都有一个开始时间和结束时间。 </li>
<li>资源：项目所需的资源包括人力、设备、资金等，这些资源是有限的。 </li>
<li>约束： 每个任务对资源的需求是不同的，同时存在任务之间的先后顺序和依赖关系。</li>
<li>优化目标： 最常见的优化目标是最小化项目完成时间或最大化资源利用率，但也可能涉及其他目标，比如最小化成本或最大化利润等。</li>
</ol>
<p>资源受限项目调度问题是一个NP-难问题，因此没有多项式时间的解法。解决该问题的方法通常包括：</p>
<ol>
<li>启发式算法： 基于经验或直觉设计的算法，如遗传算法、模拟退火等。 </li>
<li>精确算法： 尝试找到最优解的算法，如动态规划、分支定界等。但这些算法在大规模问题上的效率通常较低。 混合方法。</li>
<li>结合启发式算法和精确算法，以在可接受的时间内找到较好的解决方案。</li>
</ol>
<p>资源受限项目调度问题在许多实际应用中都有广泛的应用，包括但不限于：</p>
<ol>
<li>生产制造： 在生产线上安排任务以最大化产量并最小化成本。</li>
<li>建筑业： 安排施工工序和资源以优化工程进度和资源利用率。 </li>
<li>信息技术：安排软件开发项目中的任务和团队资源。 </li>
<li>项目管理： 规划和安排复杂项目中的任务和资源分配。</li>
</ol>
<h1 id="示例"><a href="#示例" class="headerlink" title="示例"></a>示例</h1><p>某个项目包含9个活动，活动间先后关系如图所示：<br><img src="/../images/%E6%B4%BB%E5%8A%A8%E4%BC%98%E5%85%88%E5%85%B3%E7%B3%BB.png"><br>各活动工期如下：</p>
<table>
<thead>
<tr>
<th>活动</th>
<th>活动名称</th>
<th>活动持续时间</th>
<th>资源需求量</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>活动1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>活动2</td>
<td>5</td>
<td>5</td>
</tr>
<tr>
<td>3</td>
<td>活动3</td>
<td>7</td>
<td>8</td>
</tr>
<tr>
<td>4</td>
<td>活动4</td>
<td>6</td>
<td>10</td>
</tr>
<tr>
<td>5</td>
<td>活动5</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>6</td>
<td>活动6</td>
<td>4</td>
<td>3</td>
</tr>
<tr>
<td>7</td>
<td>活动7</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>8</td>
<td>活动8</td>
<td>4</td>
<td>3</td>
</tr>
<tr>
<td>9</td>
<td>活动9</td>
<td>7</td>
<td>5</td>
</tr>
</tbody></table>
<h1 id="启发规则求解"><a href="#启发规则求解" class="headerlink" title="启发规则求解"></a>启发规则求解</h1><p>采用最短工期活动最先开始调度规则，生成上述问题的结果如下：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># %%</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">Author: TUUG</span></span><br><span class="line"><span class="string">Date: April 26, 2024 20:59</span></span><br><span class="line"><span class="string">Description: 求解资源受限项目调度问题并画图.</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> pandas <span class="keyword">as</span> pd</span><br><span class="line"><span class="keyword">from</span> collections <span class="keyword">import</span> defaultdict</span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">import</span> random</span><br><span class="line"><span class="keyword">import</span> math</span><br><span class="line"></span><br><span class="line">plt.rcParams[<span class="string">&quot;axes.labelsize&quot;</span>]=<span class="number">14</span></span><br><span class="line">plt.rcParams[<span class="string">&quot;xtick.labelsize&quot;</span>]=<span class="number">12</span></span><br><span class="line">plt.rcParams[<span class="string">&quot;ytick.labelsize&quot;</span>]=<span class="number">12</span></span><br><span class="line">plt.rcParams[<span class="string">&#x27;font.sans-serif&#x27;</span>] = [<span class="string">&#x27;SimHei&#x27;</span>]  <span class="comment"># 指定默认字体</span></span><br><span class="line">plt.rcParams[<span class="string">&#x27;axes.unicode_minus&#x27;</span>] = <span class="literal">False</span>  <span class="comment"># 解决保存图像是负号&#x27;-&#x27;显示为方块的问题</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># %%</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Activity</span>(<span class="title class_ inherited__">object</span>):</span><br><span class="line">    <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">    活动类：包含  1.活动ID  2.活动持续时间    3.活动资源需求量   4.活动紧前活动    5.活动最早开始时间  6.活动最晚开始时间  7.活动是否被访问</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, <span class="built_in">id</span>, duration, resourceRequest, successor</span>):</span><br><span class="line">        self.<span class="built_in">id</span> = <span class="built_in">id</span></span><br><span class="line">        self.time_long = duration  <span class="comment"># 活动总时长，固定不变</span></span><br><span class="line">        self.duration = duration  <span class="comment"># 活动剩余时长，动态变化</span></span><br><span class="line">        self.resourceRequest = np.array(resourceRequest)[<span class="number">0</span>]</span><br><span class="line">        self.predecessor = <span class="literal">None</span></span><br><span class="line">        self.successor = successor</span><br><span class="line">        self.visited = <span class="literal">False</span></span><br><span class="line">        self.start = <span class="literal">None</span>  <span class="comment"># 这里的start是时点数据，不是时段数据</span></span><br><span class="line">        self.end = <span class="literal">None</span></span><br><span class="line">        </span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Day</span>:</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self,<span class="built_in">id</span>,total_resource</span>):</span><br><span class="line">        self.<span class="built_in">id</span> = <span class="built_in">id</span></span><br><span class="line">        self.total_resource = total_resource</span><br><span class="line">        self.resource_used = <span class="number">0</span></span><br><span class="line">        self.resource_left = total_resource</span><br><span class="line">        self.act_list = []</span><br><span class="line">        </span><br><span class="line">    <span class="comment">#================修改代码=====================</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">start_act</span>(<span class="params">act,day,days</span>):</span><br><span class="line">    <span class="string">&quot;&quot;&quot;启动活动&quot;&quot;&quot;</span></span><br><span class="line">    <span class="keyword">if</span> act.visited == <span class="literal">False</span>:</span><br><span class="line">        act.visited = <span class="literal">True</span></span><br><span class="line">        act.start = day.<span class="built_in">id</span>-<span class="number">1</span></span><br><span class="line">        act.end = act.start + act.time_long</span><br><span class="line">        <span class="comment"># 如果活动时长大于0</span></span><br><span class="line">        <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(act.time_long):</span><br><span class="line">            execute_act(act,days[days.index(day)+i])  <span class="comment"># 这里替换为执行活动函数</span></span><br><span class="line">        <span class="keyword">if</span> act.time_long == <span class="number">0</span>:</span><br><span class="line">            execute_act(act,day)</span><br><span class="line">    </span><br><span class="line"><span class="keyword">def</span> <span class="title function_">execute_act</span>(<span class="params">act,day</span>):</span><br><span class="line">    <span class="string">&quot;&quot;&quot;执行活动&quot;&quot;&quot;</span></span><br><span class="line">    act.duration -= <span class="number">1</span></span><br><span class="line">    day.resource_used += act.resourceRequest</span><br><span class="line">    day.resource_left -= act.resourceRequest</span><br><span class="line">    day.act_list.append(act.<span class="built_in">id</span>)</span><br><span class="line">        </span><br><span class="line"><span class="keyword">def</span> <span class="title function_">can_start1</span>(<span class="params">act,day,days</span>):</span><br><span class="line">    <span class="comment"># 判断一个活动是否能开始，条件1：资源是否足够</span></span><br><span class="line">    a = days.index(day)</span><br><span class="line">    <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(act.time_long):</span><br><span class="line">        <span class="keyword">if</span> days[<span class="built_in">min</span>(a+j,<span class="built_in">len</span>(days)-<span class="number">1</span>)].resource_left &lt; act.resourceRequest:</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">    </span><br><span class="line"><span class="keyword">def</span> <span class="title function_">can_start2</span>(<span class="params">act,act_done</span>):</span><br><span class="line">    <span class="comment"># 判断一个活动是否能开始，条件2：该活动的前序活动是否已经完成</span></span><br><span class="line">    <span class="keyword">for</span> preAct <span class="keyword">in</span> act.predecessor:</span><br><span class="line">        <span class="keyword">if</span> preAct <span class="keyword">not</span> <span class="keyword">in</span> act_done:</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">pre_done</span>(<span class="params">act,act_done,activities</span>):</span><br><span class="line">    <span class="comment"># 判断活动的所有前序活动是否都已完成，返回0则说明都已经完成</span></span><br><span class="line">    ans = [<span class="number">0</span> <span class="keyword">if</span> activities[i] <span class="keyword">in</span> act_done <span class="keyword">else</span> <span class="number">1</span> <span class="keyword">for</span> i <span class="keyword">in</span> act.predecessor]</span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">sum</span>(ans) </span><br><span class="line">    <span class="comment">#================修改代码=====================</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># %%</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">read_data_from_RCP_file</span>(<span class="params">file_name</span>):</span><br><span class="line">    <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">    读取标准化文件中的所有活动信息，包括  1.活动数   2.项目资源数 3.项目资源种类数   4.项目资源限量</span></span><br><span class="line"><span class="string">    5.所有活动的ID，持续时间，资源需求，紧前活动</span></span><br><span class="line"><span class="string">    :param fileName:</span></span><br><span class="line"><span class="string">    :return: 标准化文件数据</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br><span class="line">    f = <span class="built_in">open</span>(file_name)</span><br><span class="line">    taskAndResourceType = f.readline().split(<span class="string">&#x27;      &#x27;</span>)  <span class="comment"># 第一行数据包含活动数和资源数</span></span><br><span class="line">    num_activities = <span class="built_in">int</span>(taskAndResourceType[<span class="number">0</span>])  <span class="comment"># 得到活动数</span></span><br><span class="line">    num_resource_type = <span class="built_in">int</span>(taskAndResourceType[<span class="number">1</span>])  <span class="comment"># 得到资源数</span></span><br><span class="line">    total_resource = np.array([<span class="built_in">int</span>(value) <span class="keyword">for</span> value <span class="keyword">in</span> f.readline().split(<span class="string">&#x27;      &#x27;</span>)[:-<span class="number">1</span>]])  <span class="comment"># 获取资源限量</span></span><br><span class="line">    <span class="comment"># 将每个活动的所有信息存入到对应的Activity对象中去</span></span><br><span class="line">    activities = &#123;&#125;</span><br><span class="line">    preActDict = defaultdict(<span class="keyword">lambda</span>: [])</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(num_activities):</span><br><span class="line">        nextLine = [<span class="built_in">int</span>(value) <span class="keyword">for</span> value <span class="keyword">in</span> f.readline().split(<span class="string">&#x27;      &#x27;</span>)[:-<span class="number">1</span>]]</span><br><span class="line">        <span class="comment"># task = Activity(i + 1, nextLine[0], nextLine[1:5], nextLine[6:])</span></span><br><span class="line">        task = Activity(i + <span class="number">1</span>, nextLine[<span class="number">0</span>], nextLine[<span class="number">1</span>:<span class="number">2</span>], nextLine[<span class="number">3</span>:])</span><br><span class="line">        activities[task.<span class="built_in">id</span>] = task</span><br><span class="line">        <span class="comment"># for act in nextLine[6:]:</span></span><br><span class="line">        <span class="keyword">for</span> act <span class="keyword">in</span> nextLine[<span class="number">3</span>:]:</span><br><span class="line">            preActDict[act].append(i + <span class="number">1</span>)</span><br><span class="line">    f.close()</span><br><span class="line">    <span class="comment"># 给每个活动加上紧前活动信息</span></span><br><span class="line">    <span class="keyword">for</span> actKey <span class="keyword">in</span> activities.keys():</span><br><span class="line">        activities[actKey].predecessor = preActDict[activities[actKey].<span class="built_in">id</span>].copy()</span><br><span class="line">    <span class="keyword">return</span> num_activities, num_resource_type, total_resource, activities  </span><br><span class="line"></span><br><span class="line">file_name = <span class="string">r&#x27;D:/python代码库/实验/mv9.rcp&#x27;</span></span><br><span class="line">num_activities, num_resource_type, total_resource, activities = read_data_from_RCP_file(file_name)</span><br><span class="line">total_resource = total_resource[<span class="number">0</span>]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># %%</span></span><br><span class="line">num_days = <span class="built_in">sum</span>([i.duration <span class="keyword">for</span> i <span class="keyword">in</span> activities.values()]) <span class="comment"># 总天数自动计算，不再需要手动指定</span></span><br><span class="line"><span class="comment"># num_days = 150</span></span><br><span class="line">days = [Day(i,total_resource) <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,num_days+<span class="number">1</span>)]</span><br><span class="line">act_list = [i <span class="keyword">for</span> i <span class="keyword">in</span> activities.values()]</span><br><span class="line">act_done = []</span><br><span class="line">act_candidate = [activities[<span class="number">1</span>]]</span><br><span class="line"></span><br><span class="line"><span class="comment"># %%</span></span><br><span class="line"><span class="comment"># ----------调度核心逻辑-------</span></span><br><span class="line"><span class="keyword">for</span> day <span class="keyword">in</span> days:</span><br><span class="line">    <span class="comment"># 首先考虑工期为0的活动</span></span><br><span class="line">    <span class="keyword">for</span> act <span class="keyword">in</span> act_candidate:</span><br><span class="line">        <span class="keyword">if</span> act.time_long == <span class="number">0</span>:</span><br><span class="line">            act.start = day.<span class="built_in">id</span>-<span class="number">1</span></span><br><span class="line">            act.end = day.<span class="built_in">id</span>-<span class="number">1</span></span><br><span class="line">            act_done.append(act)</span><br><span class="line">            act_candidate.remove(act)</span><br><span class="line">            <span class="comment"># act_candidate.append(act.successor)</span></span><br><span class="line">            <span class="keyword">for</span> i <span class="keyword">in</span> act.successor:</span><br><span class="line">                act_candidate.append(activities[i])</span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 遍历act_candidate列表,将能开启的工作全部启动</span></span><br><span class="line">    <span class="keyword">for</span> act <span class="keyword">in</span> act_candidate:</span><br><span class="line">        <span class="keyword">if</span> can_start1(act,day,days):</span><br><span class="line">            start_act(act,day,days)</span><br><span class="line">    <span class="comment"># -------更新act_done列表-----</span></span><br><span class="line">    <span class="keyword">for</span> act <span class="keyword">in</span> act_list:</span><br><span class="line">        <span class="keyword">if</span> act.end:</span><br><span class="line">            <span class="keyword">if</span> act.end &lt;= day.<span class="built_in">id</span> <span class="keyword">and</span> act <span class="keyword">not</span> <span class="keyword">in</span> act_done:</span><br><span class="line">                act_done.append(act)</span><br><span class="line">    <span class="comment"># 更新act_candidate列表</span></span><br><span class="line">    <span class="keyword">for</span> act <span class="keyword">in</span> act_candidate:</span><br><span class="line">        <span class="keyword">for</span> suc <span class="keyword">in</span> act.successor:</span><br><span class="line">            <span class="keyword">if</span> pre_done(activities[suc],act_done,activities) == <span class="number">0</span>:</span><br><span class="line">                act_candidate.append(activities[suc])       </span><br><span class="line">    <span class="keyword">for</span> act <span class="keyword">in</span> act_candidate:</span><br><span class="line">        <span class="keyword">if</span> act <span class="keyword">in</span> act_done:</span><br><span class="line">            act_candidate.remove(act)</span><br><span class="line"></span><br><span class="line"><span class="comment"># %%</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">plot_square</span>(<span class="params">matrix</span>):</span><br><span class="line">    <span class="comment"># plt.figure(figsize=(8, 8))</span></span><br><span class="line">    fig, ax = plt.subplots()</span><br><span class="line">    cmap = plt.get_cmap(<span class="string">&#x27;viridis&#x27;</span>)  <span class="comment"># 使用 &#x27;viridis&#x27; colormap，你可以根据需要选择其他colormap</span></span><br><span class="line">    norm = plt.Normalize(vmin=<span class="number">0</span>, vmax=matrix.<span class="built_in">max</span>())  <span class="comment"># 指定归一化范围</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(matrix.shape[<span class="number">0</span>]):</span><br><span class="line">        <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(matrix.shape[<span class="number">1</span>]):</span><br><span class="line">            color = cmap(norm(matrix[i, j]))</span><br><span class="line">            <span class="keyword">if</span> matrix[i, j] == <span class="number">0</span>:</span><br><span class="line">                color = <span class="string">&#x27;white&#x27;</span></span><br><span class="line">            square = plt.Rectangle((j, total_resource-<span class="number">1</span>-i), <span class="number">1</span>, <span class="number">1</span>, fill=<span class="literal">True</span>, color=color, edgecolor=<span class="string">&#x27;black&#x27;</span>)</span><br><span class="line">            ax.add_patch(square)</span><br><span class="line">            <span class="keyword">if</span> matrix[i, j] != <span class="number">0</span>:</span><br><span class="line">                <span class="comment"># 在正方形中心位置添加数字</span></span><br><span class="line">                plt.text(j + <span class="number">0.5</span>, total_resource-<span class="number">1</span>-i + <span class="number">0.5</span>, <span class="built_in">str</span>(matrix[i, j]), color=<span class="string">&#x27;black&#x27;</span>,fontsize=<span class="number">12</span>, ha=<span class="string">&#x27;center&#x27;</span>, va=<span class="string">&#x27;center&#x27;</span>)</span><br><span class="line">            </span><br><span class="line">    ax.set_xlim(<span class="number">0</span>, matrix.shape[<span class="number">1</span>])</span><br><span class="line">    ax.set_ylim(<span class="number">0</span>, matrix.shape[<span class="number">0</span>])</span><br><span class="line">    ax.set_aspect(<span class="string">&#x27;equal&#x27;</span>, adjustable=<span class="string">&#x27;box&#x27;</span>)</span><br><span class="line">    ax.set_xlabel(<span class="string">&#x27;日期&#x27;</span>)</span><br><span class="line">    ax.set_ylabel(<span class="string">&#x27;资源&#x27;</span>)</span><br><span class="line">    plt.title(<span class="string">&#x27;项目调度图&#x27;</span>)</span><br><span class="line">    plt.show()</span><br><span class="line"></span><br><span class="line"><span class="comment"># %%</span></span><br><span class="line">ans = [days[i].act_list <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(num_days)]</span><br><span class="line">ans.remove([])</span><br><span class="line">b = &#123;&#125;</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(activities)):</span><br><span class="line">    b[i+<span class="number">1</span>] = activities[i+<span class="number">1</span>].resourceRequest</span><br><span class="line"><span class="keyword">def</span> <span class="title function_">copy</span>(<span class="params">sub_ans,b</span>):</span><br><span class="line">    result = [item <span class="keyword">for</span> item <span class="keyword">in</span> sub_ans <span class="keyword">for</span> _ <span class="keyword">in</span> <span class="built_in">range</span>(b.get(item, <span class="number">1</span>))]</span><br><span class="line">    <span class="keyword">return</span> result</span><br><span class="line">ans_new = [[]] * <span class="built_in">len</span>(ans)</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(ans)):</span><br><span class="line">    ans_new[i] = copy(ans[i],b)</span><br><span class="line"><span class="comment"># print(ans_new)</span></span><br><span class="line"><span class="comment"># print(&#x27;--------------各活动开始时间----------------&#x27;)</span></span><br><span class="line">start_time = []</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="built_in">len</span>(activities)+<span class="number">1</span>):</span><br><span class="line">    <span class="comment"># print(&#x27;活动&#x27;+str(i)+&#x27;开始于&#x27;+str(activities[i].start))</span></span><br><span class="line">    start_time.append(activities[i].start)</span><br><span class="line"><span class="comment"># print(start_time)</span></span><br><span class="line"><span class="comment"># print(&#x27;-------------活动总工期----------------&#x27;)</span></span><br><span class="line">total_time = <span class="number">0</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="built_in">len</span>(activities)+<span class="number">1</span>):</span><br><span class="line">    <span class="keyword">if</span> activities[i].successor == []:</span><br><span class="line">        total_time = activities[i].end+<span class="number">1</span></span><br><span class="line"><span class="comment"># print(total_time)</span></span><br><span class="line"><span class="comment"># 转成矩阵</span></span><br><span class="line">a = np.zeros((total_resource,<span class="built_in">len</span>(ans_new)),dtype=<span class="built_in">int</span>)</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(ans_new)):</span><br><span class="line">    <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(ans_new[i])):</span><br><span class="line">        a[total_resource-<span class="number">1</span>-j,i] = <span class="built_in">int</span>(ans_new[i][j])</span><br><span class="line"></span><br><span class="line">plot_square(a)</span><br><span class="line"><span class="comment"># print(a)</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1 id="求解结果"><a href="#求解结果" class="headerlink" title="求解结果"></a>求解结果</h1><p>采用上述代码求解的项目调度图如图所示：<br><img src="/../images/%E9%BB%98%E8%AE%A4%E9%A1%BA%E5%BA%8F%E8%B0%83%E5%BA%A6%E6%96%B9%E6%A1%88.png"></p>
<p>采用最短时间活动最先开始规则生成图如下：<br><img src="/../images/%E5%90%AF%E5%8F%91%E8%A7%84%E5%88%99%E8%B0%83%E5%BA%A6%E6%96%B9%E6%A1%88.png"></p>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="reward-container">
  <div>请我一杯咖啡吧！</div>
  <button>
    赞赏
  </button>
  <div class="post-reward">
      <div>
        <img src="/images/wechatpay.png" alt="TUUG 微信">
        <span>微信</span>
      </div>
      <div>
        <img src="/images/alipay.png" alt="TUUG 支付宝">
        <span>支付宝</span>
      </div>

  </div>
</div>

          <div class="post-tags">
              <a href="/tags/%E9%A1%B9%E7%9B%AE%E8%B0%83%E5%BA%A6%EF%BC%8C%E5%90%AF%E5%8F%91%E5%BC%8F%E8%A7%84%E5%88%99/" rel="tag"># 项目调度，启发式规则</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2024/05/06/epsilon-%E7%BA%A6%E6%9D%9F%E6%96%B9%E6%B3%95/" rel="prev" title="epsilon-约束方法">
                  <i class="fa fa-angle-left"></i> epsilon-约束方法
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2024/05/06/%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2Graphhopper%E5%AE%9E%E7%8E%B0%E7%A6%BB%E7%BA%BF%E5%9C%B0%E5%9B%BE%E8%B7%AF%E5%BE%84%E8%A7%84%E5%88%92%E5%8A%9F%E8%83%BD%EF%BC%88%E5%B0%8F%E7%99%BD%E6%94%BE%E5%BF%83%E9%A3%9F%E7%94%A8%E7%89%88%EF%BC%89/" rel="next" title="本地部署Graphhopper实现离线地图路径规划功能（小白放心食用版）">
                  本地部署Graphhopper实现离线地图路径规划功能（小白放心食用版） <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 
    <span itemprop="copyrightYear">2024</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">TUUG</span>
  </div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>

<!-- 网站运行时间的设置 -->
<span id="timeDate">载入天数...</span>
<span id="times">载入时分秒...</span>
<script>
    var now = new Date();
    function createtime() {
        var grt= new Date("05/04/2024 10:00:00"); //此处修改你的建站时间或者网站上线时间
        now.setTime(now.getTime()+250);
        days = (now - grt ) / 1000 / 60 / 60 / 24; dnum = Math.floor(days);
        hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum); hnum = Math.floor(hours);
        if(String(hnum).length ==1 ){hnum = "0" + hnum;} minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum);
        mnum = Math.floor(minutes); if(String(mnum).length ==1 ){mnum = "0" + mnum;}
        seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
        snum = Math.round(seconds); if(String(snum).length ==1 ){snum = "0" + snum;}
        document.getElementById("timeDate").innerHTML = "本站已安全运行 "+dnum+" 天 ";
        document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒.";
    }
setInterval("createtime()",250);
</script>

    </div>
  </footer>

  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>
  <div class="sidebar-dimmer"></div>
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/sidebar.js"></script><script src="/js/next-boot.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>







  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>



  <script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>
  
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"log":false,"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true}});</script></body>
</html>
